<?php
/*
 |--------------------------------------------------------------------------
 | SkyCaiji (蓝天采集器)
 |--------------------------------------------------------------------------
 | Copyright (c) 2018 http://www.skycaiji.com All rights reserved.
 |--------------------------------------------------------------------------
 | 使用协议  http://www.skycaiji.com/licenses
 |--------------------------------------------------------------------------
 */

namespace Admin\Event; use Think\Controller; use Admin\Controller\BaseController; use Think\Storage; if(!defined('IN_SKYCAIJI')) { exit('NOT IN SKYCAIJI'); } class ReleaseBaseEvent extends BaseController{ public function record_collected($url,$returnData,&$release){ if($returnData['id']>0){ D('Collected')->add(array( 'url' => $url, 'urlMd5' => md5 ( $url ), 'target' => $returnData['target'], 'desc' => $returnData['desc']?$returnData['desc']:'', 'error'=>'', 'task_id' => $release ['task_id'], 'release' => $release['module'], 'addtime'=>time() )); if(!empty($returnData['target'])){ $target=$returnData['target']; if(preg_match('/^http(s){0,1}\:\/\//i',$target)){ $target='<a href="'.$target.'" target="_blank">'.$target.'</a>'; } $this->echo_msg("成功将<a href='{$url}' target='_blank'>内容</a>发布至：{$target}",'black'); }else{ $this->echo_msg("成功发布：<a href='{$url}' target='_blank'>{$url}</a>",'black'); } }else{ if(!empty($returnData['error'])){ D('Collected')->add(array( 'url' => $url, 'urlMd5' => md5 ( $url ), 'target' => '', 'desc'=>'', 'error' => $returnData['error'], 'task_id' => $release ['task_id'], 'release' => $release['module'], 'addtime'=>time() )); $this->echo_msg($returnData['error']."：<a href='{$url}' target='_blank'>{$url}</a>"); } } } public function get_field_val($collFieldVal){ if(empty($collFieldVal)){ return ''; } $val=$collFieldVal['value']; if(!empty($GLOBALS['config']['caiji']['download_img'])){ if(!empty($collFieldVal['img'])){ if(!is_array($collFieldVal['img'])){ $collFieldVal['img']=array($collFieldVal['img']); } foreach ($collFieldVal['img'] as $imgUrl){ $newImgUrl=$this->download_img($imgUrl); if($newImgUrl!=$imgUrl){ $val=str_replace($imgUrl, $newImgUrl, $val); } } } } return $val; } public function download_img($url){ if(empty($url)){ return ''; } if(!preg_match('/^\w+\:\/\//',$url)){ return $url; } static $imgList=array(); $key=md5($url); if(!isset($imgList[$key])){ if(preg_match('/\.(jpg|jpeg|gif|png)\b/i',$url,$prop)){ $prop=strtolower($prop[1]); }else{ $prop='jpg'; } $fileimg='/data/images/'.date('Y-m-d',NOW_TIME).'/'.$key.'.'.$prop; $filename=C('ROOTPATH').$fileimg; if(!file_exists($filename)){ $request=\Requests::get($url,null,array('timeout'=>0)); if(200==$request->status_code&&!empty($request->body)){ if(Storage::put($filename,$request->body,'F')){ $imgList[$key]=C('ROOTURL').$fileimg; } } }else{ $imgList[$key]=C('ROOTURL').$fileimg; } } return empty($imgList[$key])?$url:$imgList[$key]; } public function utf8_to_charset($charset,$val){ static $chars=array('utf-8','utf8','utf8mb4'); if(!in_array(strtolower($charset),$chars)){ if(!empty($val)){ $val=iconv('utf-8',$charset.'//IGNORE',$val); } } return $val; } public function auto_convert2utf8($arr){ $arr=array_array_map('auto_convert2utf8',$arr); return $arr; } } ?>